#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t id = fork();
    
    if (id == 0)
    {
        printf("begin running pid: %d, ppid: %d\n", getpid(), getppid());
        
        //execl("/usr/bin/python3", "python3", "test.py", NULL);
        execl("/usr/bin/bash", "bash", "test.sh", NULL);
        
        printf("runn end pid: %d, ppid: %d\n", getpid(), getppid());
        exit(1);
    }
    else if (id > 0)
    {
        int state = 0;
        pid_t ret = waitpid(id, &state, 0);
        if (ret == id)
        {
            printf("wait id = %d\nexit code: %d\n", ret, WEXITSTATUS(state));
            if (!WIFEXITED(state))
                printf("sig code: %d\n", state & 0x7F);
        }
        else
            printf("wait error\n");
    }
    else
        printf("fork error\n");

    return 0;
}
